package controller;

import dao.CarDAOImpl;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        resp.setContentType("application/json;charset=utf8");
        resp.setCharacterEncoding("utf8");

        //获取打印输出流,向网页输出内容
        PrintWriter writer = resp.getWriter();

        String userName = req.getParameter("userName");
        String passwd = req.getParameter("password");
        CarDAOImpl dao = new CarDAOImpl();
        User user = dao.login(userName, passwd);

        if (user!=null){
            writer.print("登录成功");
        }else{
            writer.print("登录失败");
        }
        writer.close();
    }
}
